/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tp2ia_partie2.objects;

import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;

/**
 *
 * @author hp
 */
public class Clause {

    //liste de littereaux du clause
    Set<Litteral> litteraux;

    public Clause() {
    }

    public Clause(Set<Litteral> litteraux) {
        this.litteraux = litteraux;
    }

    public Set<Litteral> getLitteraux() {
        return litteraux;
    }

    public void setLitteraux(Set<Litteral> litteraux) {
        this.litteraux = litteraux;
    }

    public Set<Litteral> getPositiveLitteraux() {
        Set<Litteral> positiveLitteraux = new LinkedHashSet<Litteral>();
        System.out.println("_getPos");
        for (Litteral lit : litteraux) {
            System.out.println("is " + lit + " pos?");
            if (!lit.isNegation()) {
                System.out.println("oui");
                positiveLitteraux.add(lit);
            }
        }
        return positiveLitteraux;
    }

    public Set<Litteral> getNegativeLitteraux() {
        Set<Litteral> negativeLitteraux = new LinkedHashSet<Litteral>();
        System.out.println("getNeg");
        for (Litteral lit : litteraux) {
            System.out.println("is " + lit + " neg?");
            if (lit.isNegation()) {
                System.out.println("oui");
                negativeLitteraux.add(lit);
            }
        }
        return negativeLitteraux;
    }

    public Clause getActiveLitteraux() {
        Clause Cresult = new Clause();
        Set<Litteral> Lresult = new LinkedHashSet<>();

        for (Litteral lit : litteraux) {
            if (lit.estActive()) {
                Lresult.add(lit);
            }
        }
        if (Lresult.size() == 0) {
            return null;
        }
        Cresult.setLitteraux(Lresult);
        return Cresult;
    }

    public String toString() {
        String msg = "Clause{ ";
        for (Litteral lit : litteraux) {
            msg += "" + lit + " ";
        }
        return msg +"}";
    }

    public Clause toSimpleClause() {

        return new Clause(this.litteraux);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Clause other = (Clause) obj;
        if (!Objects.equals(this.litteraux, other.litteraux)) {
            return false;
        }
        return true;
    }

}
